home *** CD-ROM | disk | FTP | other *** search
- Path: anvil.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: What is &Variable (declared as: char Variable[10])?
- Date: 28 Feb 1996 11:06:15 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4h2937INN8gb@anvil.ugrad.cs.ubc.ca>
- References: <4gqpa1$3h9@alcor.usc.edu> <4gtab6$acb@ceylon.gte.com> <313318b8.53776146@nntp.ix.netcom.com> <4h1u9d$sqq@ceylon.gte.com>
- NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
-
- In article <4h1u9d$sqq@ceylon.gte.com>, Brenda <g051286> wrote:
-
- >What is the definition of a pointer? I have always been taught that a
-
- A pointer is an object which holds the address of another object.
-
- >pointer is simply an address in memory, and an array name (i.e. myarray)
- >is simply a CONSTANT address. I don't think this statement is all that
-
- An array _has_ a constant address. But it an address it is not. It's not a
- pointer because an array is not an object which holds the address of
- another object. It can have elements which are pointers, of course.
-
- >radical. Of course there are differences between arrays and pointers
-
- Well, it is radical, because what is understood by ``constant'' in C is different
- from what you mean. A constant is an object which holds a value that is
- initialized once but doesn't change. You designate this by modifying its type
- with a ``const'' attribute. Another meaning of ``constant'' is ``literal
- constant''---a number, character or string literal. A third meaning is
- ``pre-processor constant''.
-
- >due to the fact that an array is a CONSTANT address and a pointer is a
- >VARIABLE address. And the reason I said you shouldn't (note shouldn't
- >not couldn't) say &myarray is:
-
- >
- >==================================================
- >(from "A Book On C", Kelley & Pohl, pg 200)
- >Constructs not to be pointed at:
- >1. Do not point at constants. (&3)
- >2. Do not point at arrays; an array name is a constant. (int a[77]; &a)
-
- If this book was written after the publication of K&R2, it should be considered
- poorly researched. Sell this book immediately.
-
- An array name is not a constant, it is the name of an array object. The C
- language has no true constants like Pascal, it only has pre-processor
- constants, literals, and variables that can be initialized but not assigned to
- (const qualifier).
-
- Pointing at arrays is valid, and an important feature of ANSI C.
-
- >3. Do not point at ordinary expressions &(k + 99)
-
- This is stupid, because it suggests that the assertion supports a
- counterfactual; i.e. that you _can_ point at such expressions, but that you
- _shouldn't_. In fact, the compiler will reject that, depending on the type of
- expression.
-
- There is no such thing as ``ordinary expression''; the introduction of such at
- term is misleading.
-
- >4. Do not point at register variables. (register v; &v)
-
- Compilers will reject this. Again, this is something that you simply cannot do.
-
- What is the point of including things that cannot be done in a list of things
- that shouldn't be done? The authors clearly lack the intellectual rigor to be
- writing about matters related to computer science.
-
- >The address operator can be applied to variables and array elements.
-
- This contradicts their earlier assertion that it cannot be applied to arrays,
- which are variables. It can also be applied to functions.
-
- >===================================================
- >
- >So again I say, myarray is DEFINITELY a pointer (i.e. address in memory).
-
- According to your book. Not all that is printed is the truth.
-
-
- If myarray is a pointer to char, why is it not the case that
-
- char myarray[131];
-
- if (sizeof(myarray) == sizeof(char *))
- puts("Yes!\n");
-
- fails to produce a Yes? Would not two pointers to char have the same size?
- --
-
-